class Solution {
public:
    string reverseStr(string s, int k) {
        for(int i = 0; i < s.length() + (2 * k - 1) / (2 * k); ++i){
            int start = i * 2 * k;
            int end = s.length() < (i * 2 + 1) * k ? s.length() : (i * 2 + 1) * k;
            for(int j = 0; j < (end - start) / 2; ++j) {
                char temp = s[start + j];
                s[start + j] = s[end - 1 - j];
                s[end  - 1 - j] = temp;
            }
        }
        
        return s;
    }
};